<?php

define(IMPORT,'../class.mamatblog/',true);
require_once(IMPORT.'mysql.php');
require_once(IMPORT.'comment.php');
require_once(IMPORT.'page.php');	
require_once(IMPORT.'feedcreator.class.php');	

//page
$pageMain = new Page();
$pageDetail = $pageMain->getMainPage();


function parseDate($str){
	$data = explode(" ",$str);
	$datatgl = explode("-",$data[0]);
	$datatime = explode(":",$data[1]);
	return mktime($datatime[0],$datatime[1],$datatime[2],$datatgl[1],$datatgl[2],$datatgl[0]);
	
}

$rss = new UniversalFeedCreator();
$rss->useCached(); // use cached version if age<1 hour
$rss->title = "Mamat Zone";
$rss->description = "All about Mamat :P";


//optional
//$rss->descriptionTruncSize = 500;
//$rss->descriptionHtmlSyndicated = true;

$rss->link = "http://mamat.amikom.ac.id/";
$rss->syndicationURL = "http://mamat.amikom.ac.id";


// get your news items from somewhere, e.g. your database:
for($i = 0; $i < count($pageDetail);$i++){
    $item = new FeedItem();
    $item->title = $pageDetail[$i][2];
    $item->link = "http://mamat.amikom.ac.id/main/pagedetail.php?pid=".$pageDetail[$i][0];
    $item->description = $pageMain->parseStr(nl2br( ereg_replace( "\[/code\]"," ",ereg_replace("\[code\]"," ",$pageDetail[$i][3]) )),150);

    
	//optional
    //item->descriptionTruncSize = 500;
    //item->descriptionHtmlSyndicated = true;
	
	
    $item->date = parseDate($pageDetail[$i][1]);
	$item->source = "http://mamat.amikom.ac.id/main/pagedetail.php?pid=".$pageDetail[$i][0];
    $item->author = $pageMain->getPageAuthor($pageDetail[$i][5]);

    $rss->addItem($item);
}

// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),
// MBOX, OPML, ATOM, ATOM0.3, HTML, JS
echo $rss->saveFeed("RSS2.0", "../caching/feed.xml");
//echo $rss->saveFeed("RSS2.0");

?>